def min(A,k,step) :

    min = A[k-step]
    for i in xrange(k-step, k) :
        if min > A[i] :
            min = A[i]

    return min

def main():
    D_INPUT = True

    if D_INPUT:
        stairs = input()
        step = input()
    else:
        stairs = (5, 3, 6, 1, 1, 2, 3, 4, 7, 5, 5, 7, 1, 1, 4, 6, 3, 4, 7, 4, 2)
        step = 4

    if len(stairs) <= step : return stairs[len(stairs)-1]

    A = []
    for k in xrange(step) :
        A.append(stairs[k])

    for k in xrange(step, len(stairs)) :
        A.append(stairs[k] + min(A,k,step))

    print A.pop()

main()